/**
 * @param {string} s
 * @return {number}
 */
 var countPalindromicSubsequence = function(s) {
    let ans = 0
    const sset = new Set()
    for(let i = 0;i<s.length; i++){
        if(sset.has(s[i])){
            continue
        }
        let x = s[i], idx = s.length-1
        while(s[idx] !== x){
            idx--
        }
        ans += new Set(s.slice(i+1, idx).split('')).size
        sset.add(s[i])
    }
    return ans
};

